<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.completion.InBufferCompleter</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_completion doc_spec_completion_in_buffer_completer_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../../'>Howl 0.3 Documentation</a></li><li>Spec</li><li>Completion</li><li>Spec - howl.completion.InBufferCompleter</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.completion.inbuffercompleter">howl.completion.InBufferCompleter</h1>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="complete">complete<span class="arg-list">()</span></h2>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="n">lines</span><span class="w">&#x000A;</span><span class="n">factory</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">completion</span><span class="p">.</span><span class="n">in_buffer</span><span class="p">.</span><span class="n">factory</span><span class="w">&#x000A;&#x000A;</span><span class="n">complete_at</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">pos</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">context</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="o">\</span><span class="n">context_at</span><span class="w"> </span><span class="n">pos</span><span class="w">&#x000A;  </span><span class="n">completer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">factory</span><span class="w"> </span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="n">context</span><span class="w">&#x000A;  </span><span class="n">completer</span><span class="o">\</span><span class="n">complete</span><span class="w"> </span><span class="n">context</span><span class="w">&#x000A;&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;  </span><span class="n">lines</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">lines</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="returns-completions-for-local-matches-in-the-buffer">returns completions for local matches in the buffer</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="sh">[[&#x000A;Hello there&#x000A;  some symbol (foo) {&#x000A;    if yike {&#x000A;say_it = 'blarg'&#x000A;s&#x000A;    }&#x000A;  }&#x000A;&#x000A;  other sion (arg) {&#x000A;    saphire = 'that too'&#x000A;  }&#x000A;]]</span><span class="w">&#x000A;</span><span class="n">comps</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">complete_at</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">5</span><span class="p">].</span><span class="n">end_pos</span><span class="w">&#x000A;</span><span class="nb">table.sort</span><span class="w"> </span><span class="n">comps</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'saphire'</span><span class="p">,</span><span class="w"> </span><span class="s1">'say_it'</span><span class="p">,</span><span class="w"> </span><span class="s1">'sion'</span><span class="p">,</span><span class="w"> </span><span class="s1">'some'</span><span class="p">,</span><span class="w"> </span><span class="s1">'symbol'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">comps</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="does-not-include-the-token-being-completed-itself">does not include the token being completed itself</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="sh">[[&#x000A;text&#x000A;te&#x000A;noice&#x000A;test&#x000A;]]</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'text'</span><span class="p">,</span><span class="w"> </span><span class="s1">'test'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">complete_at</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">end_pos</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'test'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">complete_at</span><span class="w"> </span><span class="mi">3</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="favours-matches-close-to-the-current-position">favours matches close to the current position</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="sh">[[&#x000A;two&#x000A;twitter&#x000A;tw&#x000A;other&#x000A;and other&#x000A;twice&#x000A;twitter&#x000A;]]</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'twitter'</span><span class="p">,</span><span class="w"> </span><span class="s1">'two'</span><span class="p">,</span><span class="w"> </span><span class="s1">'twice'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">complete_at</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">end_pos</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="offers-&quot;smart&quot;-completions-after-the-local-ones">offers &quot;smart&quot; completions after the local ones</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="sh">[[&#x000A;two&#x000A;twitter&#x000A;_fatwa&#x000A;tw&#x000A;the_water&#x000A;]]</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'twitter'</span><span class="p">,</span><span class="w"> </span><span class="s1">'two'</span><span class="p">,</span><span class="w"> </span><span class="s1">'the_water'</span><span class="p">,</span><span class="w"> </span><span class="s1">'_fatwa'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">complete_at</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">4</span><span class="p">].</span><span class="n">end_pos</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="works-with-unicode">works with unicode</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="sh">[[&#x000A;hellö&#x000A;häst&#x000A;h&#x000A;]]</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'häst'</span><span class="p">,</span><span class="w"> </span><span class="s1">'hellö'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">complete_at</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">end_pos</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="detects-existing-words-using-the-word_pattern-variable">detects existing words using the word_pattern variable</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="sh">[[&#x000A;*foo*/-bar&#x000A;eat.food.&#x000A;*&#x000A;oo&#x000A;]]</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">word_pattern</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'[^/%s.]+'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'*foo*'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">complete_at</span><span class="w"> </span><span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">].</span><span class="n">end_pos</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(multiple buffers)</span></h3>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">buffer2</span><span class="p">,</span><span class="w"> </span><span class="n">buffer3</span><span class="w">&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">close_all_buffers</span><span class="o">!</span><span class="w">&#x000A;&#x000A;  </span><span class="n">buffer2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w">&#x000A;  </span><span class="n">buffer2</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'foo\n'</span><span class="w">&#x000A;  </span><span class="n">app</span><span class="o">\</span><span class="n">add_buffer</span><span class="w"> </span><span class="n">buffer2</span><span class="p">,</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;  </span><span class="n">buffer2</span><span class="p">.</span><span class="n">last_shown</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">123</span><span class="w">&#x000A;&#x000A;  </span><span class="n">buffer3</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w">&#x000A;  </span><span class="n">buffer3</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'fabulous\n'</span><span class="w">&#x000A;  </span><span class="n">buffer3</span><span class="p">.</span><span class="n">last_shown</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">12</span><span class="w">&#x000A;  </span><span class="n">app</span><span class="o">\</span><span class="n">add_buffer</span><span class="w"> </span><span class="n">buffer3</span><span class="p">,</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;&#x000A;</span><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">app</span><span class="o">\</span><span class="n">close_buffer</span><span class="w"> </span><span class="n">buffer2</span><span class="p">,</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">app</span><span class="o">\</span><span class="n">close_buffer</span><span class="w"> </span><span class="n">buffer3</span><span class="p">,</span><span class="w"> </span><span class="kc">true</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="searches-up-to-&lt;config.inbuffer_completion_max_buffers&gt;-other-buffers">searches up to &lt;config.inbuffer_completion_max_buffers&gt; other buffers</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'fry\nf'</span><span class="w">&#x000A;</span><span class="n">comps</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">complete_at</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">end_pos</span><span class="w">&#x000A;</span><span class="nb">table.sort</span><span class="w"> </span><span class="n">comps</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'fabulous'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'fry'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">comps</span><span class="w">&#x000A;&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">inbuffer_completion_max_buffers</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w">&#x000A;</span><span class="n">comps</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">complete_at</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">end_pos</span><span class="w">&#x000A;</span><span class="nb">table.sort</span><span class="w"> </span><span class="n">comps</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'fry'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">comps</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="prefers-closer-matches">prefers closer matches</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'fry\nf'</span><span class="w">&#x000A;</span><span class="n">comps</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">complete_at</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">end_pos</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'fry'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'fabulous'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">comps</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="skips-buffers-with-a-different-mode-if-&lt;config.inbuffer_completion_same_mode_only&gt;-is-true">skips buffers with a different mode if &lt;config.inbuffer_completion_same_mode_only&gt; is true</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">buffer</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">inbuffer_completion_same_mode_only</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">buffer2</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'fry\nf'</span><span class="w">&#x000A;</span><span class="n">comps</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">complete_at</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">end_pos</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'fry'</span><span class="p">,</span><span class="w"> </span><span class="s1">'fabulous'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">comps</span><span class="w">&#x000A;&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">inbuffer_completion_same_mode_only</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;</span><span class="n">comps</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">complete_at</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">].</span><span class="n">end_pos</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'fry'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'fabulous'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">comps</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2015
            <a class='alert-link' href='https://github.com/nilnor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
